<?php
namespace app\common\model;
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2016/9/18
 * Time: 10:36
 */
class User extends \think\Model
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'reg_time'; //指定时间字段
    protected $updateTime = false;
   /* protected $type = [
        'file'    =>  'serialize'
    ];*/
    protected $insert = ['reg_ip','login_time'];
    public function userInfo(){
        return $this->hasOne('user_info','uid','id',[],'left');
    }
    protected function getModelAttr($value){
        $data = $this->modelArr();
        return $data[$value];
    }
    public function modelArr(){
        $data = [
            1 => '个人用户',
            2 => '经纪人'
        ];
        return $data;
    }
    protected function setRegIpAttr()
    {
        return request()->ip();
    }
    protected function setLoginTimeAttr(){
        return time();
    }
    protected function setPasswordAttr($value){
        if(!empty($value)){
            return passwordEncode($value);
        }
        return '';
    }
}